'use strict';

const Controller = require('../../core/common');

class DashboardsController extends Controller {

  async index() {
    const { ctx } = this;
    const { userId } = ctx.request.query;

    // 我的幸运草
    const { amount = 0 } = await ctx.model.Integrals.findOne({
      where: { userId },
      order: [
        ['id', 'DESC']
      ],
    }) || {};
    // 我的全部抽奖
    const join = await ctx.model.UsersGoods.count({
      where: { userId, status: 0 }
    });
    // 我发起的抽奖
    const launch = await ctx.model.UsersGoods.count({
      where: { userId, status: 1 }
    });
    // 我的中奖记录
    const winning = await ctx.model.UsersGoods.count({
      where: { userId, status: 2 }
    });

    this.success({ amount, join, launch, winning });
  }

  async show() {
    const { ctx } = this;

    const data = await ctx.service.v1.dashboards.findAll();

    this.success(data);

  }

  async create() {
    const { ctx } = this;

    const data = await ctx.service.v1.dashboards.create();

  }

}

module.exports = DashboardsController;